#include "connector.hpp"
#include "event_loop.hpp"
#include "event_trace.hpp"
#include <error.h>

using namespace event_framework;

 bool Connector::Connect(const EndPoint& peer)
{
    if (socket.Connect(peer) < 0)
    {
        EVENT_TRACE_ERROR("[Connector::Connect] connect " << peer << " failed with err=" << error);
        return false;
    }
    if (callback)
    {
        callback(socket);
    }
    else
    {
        socket.Close();
    }
    return true;
}